package com.mentalhealthplatform.studentV3.repository;

import com.mentalhealthplatform.appModels.Assessment;
import com.mentalhealthplatform.appModels.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

/**
 * @author Pear
 */
@Repository
public interface AssessmentRepositoryV3 extends JpaRepository<Assessment, Integer> {

    @Query("SELECT a FROM Assessment a JOIN a.student s WHERE " +
            "( :college IS NULL OR s.college = :college) AND " +
            "( :major IS NULL OR s.major = :major) AND " +
            "( :minAge IS NULL OR (YEAR(CURRENT_DATE) - YEAR(s.birthDate)) >= :minAge) AND " +
            "( :maxAge IS NULL OR (YEAR(CURRENT_DATE) - YEAR(s.birthDate)) <= :maxAge) AND " +
            "( :gender IS NULL OR s.gender = :gender) AND " +
            "( :grade IS NULL OR s.grade = :grade)")
    List<Assessment> findByFilterParams(
            @Param("college") String college,
            @Param("major") String major,
            @Param("minAge") Integer minAge,
            @Param("maxAge") Integer maxAge,
            @Param("gender") String gender,
            @Param("grade") String grade);

    List<Assessment> findByStudent(Student student); // 根据学生查找测评

    List<Assessment> findByStudentId(Student student);
    @Query("SELECT a FROM Assessment a WHERE a.studentId = :studentId")
    List<Assessment> findByStudentId(@Param("studentId") UUID studentId);
}
